﻿using System.IO;
using System.Reflection;
using GuidanceExplorer.Model;
using GuidanceExplorerAddIn.Services;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GuidanceExplorerAddinTest
{
    
    
    /// <summary>
    ///This is a test class for AddinModelStorageServiceTest and is intended
    ///to contain all AddinModelStorageServiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class AddinModelStorageServiceTest
    {


        private TestContext testContextInstance;
        private static string currentDirectory ;
            
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
         
        //You can use the following additional attributes as you write your tests:
        
        //Use ClassInitialize to run code before running the first test in the class
        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            currentDirectory = Path.GetDirectoryName(
                    Assembly.GetExecutingAssembly().Location);
        }
        
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for LoadGuidance
        ///</summary>
        [DeploymentItem("GuidanceTypes.xml"), TestMethod(), DeploymentItem("GuidanceExplorerAddin.dll.config")]
        public void LoadGuidanceTest()
        {            
            AddinModelStorageService target = new AddinModelStorageService();
            LoadGuidance(target);  
        }

        private static Guidance LoadGuidance(AddinModelStorageService target)
        {
            ClientFlavour clientFlavour = ClientFlavour.Offline;
            Guidance guidance = target.LoadGuidance(currentDirectory, clientFlavour);
            Assert.IsNotNull(guidance);
            Assert.IsNotNull(guidance.Libraries);
            Assert.IsNotNull(guidance.UserViews);
            Assert.IsTrue(guidance.HasItems);
            return guidance;
        }
        [DeploymentItem("GuidanceTypes.xml"),DeploymentItem("GuidanceExplorerAddin.dll.config"), TestMethod()]
        public void SaveGuidanceTest()
        {
            AddinModelStorageService target = new AddinModelStorageService();
            target.SaveGuidance(LoadGuidance(target), currentDirectory);
            
        }
        [DeploymentItem("GuidanceTypes.xml"),DeploymentItem("GuidanceExplorerAddin.dll.config"), TestMethod()]
        public void LoadAddinGuidanceTest()
        {
            AddinModelStorageService target =LoadAddinGuidance();
            Assert.IsNotNull(target.Guidance);
            Assert.IsNotNull(target.Guidance.Libraries);
            Assert.IsNotNull(target.Guidance.UserViews);
            Assert.IsTrue(target.Guidance.HasItems);
        }

        private static AddinModelStorageService LoadAddinGuidance()
        {
            AddinModelStorageService target = new AddinModelStorageService();
            target.LoadSolutionGuidance("TestSolution", @"\TestSolution");
            return target;
        }

        [DeploymentItem("GuidanceTypes.xml"), TestMethod(), DeploymentItem("GuidanceExplorerAddin.dll.config")]
        public void SaveAddinGuidanceTest()
        {
            AddinModelStorageService target = LoadAddinGuidance();
            target.SaveSolutionGuidance();
            
        }
    }
}
